/**Treatment Record presenter**/
// $codepro.audit.disable largeNumberOfParameters
package edu.gatech.presenters;

import javax.swing.JOptionPane;

import edu.gatech.datastorage.DoctorsOrders;
import edu.gatech.datastorage.TreatmentRecord;
import edu.gatech.gui.DoctorsOrdersPanel;
import edu.gatech.userclasses.Doctor;
import edu.gatech.userclasses.Patient;
import edu.gatech.utilities.Persistence;

/**
 * Creates a treatment record for a patient
 * @author Tyler Natoli
 * @version 1.0
 */
public class TreatmentRecordPresenter {
	
	 /** Patient that is getting record added to it**/
	private final Patient currentPatient;
	
	/** Sets the patient from the GUI
	 * 
	 * @param currentPatient
	 */
	public TreatmentRecordPresenter(Patient currentPatient){
		this.currentPatient = currentPatient;
	}
	
	/** Adds a treatment record to a patient
	 * 
	 * @param doctor
	 * @param nurse
	 * @param symptoms
	 * @param bloodPreassure
	 * @param temperature
	 * @param height
	 * @param weight
	 * @param diagnosis
	 */
	public void addRecord(String doctor, String nurse, String symptoms, 
			String bloodPreassure, String temperature, String height,
			String weight, String diagnosis){
		final TreatmentRecord record = currentPatient.getInfo().getLastRecord();
		record.setDiagnosis(diagnosis);
		record.setDoctor(doctor);
		record.setNurse(nurse);
		final String vitalSigns = bloodPreassure + " " + temperature + " " 
		+ height + " " + weight;
		record.setVitalSigns(vitalSigns);
		record.setSymptoms(symptoms);
		currentPatient.getInfo().setPendingAppointment(false);
		Persistence.save();
		JOptionPane.showMessageDialog(null, "Treatment Record has been added to patient");
	}
	
	/**
	 * Shows the reports of a patient
	 */
	public void viewReports(){
		final DoctorsOrders orders = currentPatient.getInfo().getLastRecord().getOrders();
		if(orders != null){
			JOptionPane.showMessageDialog(null, orders.toString());
		}
		else{
			JOptionPane.showMessageDialog(null, "No doctors orders have been added yet");
		}
	}
	
	/**
	 * Adds Dictors orders to a patient
	 * @param doctor
	 */
	public void addDoctorOrder(Doctor doctor){
		final DoctorsOrdersPanel panel = new DoctorsOrdersPanel(currentPatient, doctor); // $codepro.audit.disable staticInstantiation, variableUsage
	}
	
	/** Overrides toString
	 * @return String
	 */
	public String toString(){
		return "Treatment record presenter";
	}
	
	/**
	 * Delete the latest doctors order
	 */
	public void deleteOrder(){
		if(currentPatient.getInfo().getLastRecord().getOrders() != null){
			currentPatient.getInfo().getLastRecord().deleteOrders();
		}
		JOptionPane.showMessageDialog(null, "Doctors orders have been cleared");
	}
}
